﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DSS_XNA.Engine.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using DSS_XNA.Engine.World;

namespace DSS_XNA.Engine.Objects
{
    public class Object : Sprite
    {
        #region Properties

        public IWorld World
        {
            get { return _world; }
            set { _world = value; }
        }
        private IWorld _world = null;

        public bool IsExpiring
        {
            get { return _isExpiring; }
            set { _isExpiring = value; }
        }
        private bool _isExpiring = false;

        public delegate void OnExpireDelegate(Object obj);
        public event OnExpireDelegate ExpireEvent;

        #endregion

        #region Public Methods

        public Object()
        {
        }

        public bool Load(IWorld world, ContentManager content, string name, string assetName, float width, float height)
        {
            this.World = world;
            this.Name = name;
            this.Texture = content.Load<Texture2D>(assetName);
            this.WidthInMeters = width;
            this.HeightInMeters = height;

            this.World.Objects.Add(this);

            return true;
        }

        public void Expire()
        {
            this.World.ExpiredObjects.Add(this);
            this._isExpiring = true;

            if (this.ExpireEvent != null)
                this.ExpireEvent(this);
        }

        #endregion
    }
}
